import hudson.model.*;

pipeline {
    agent any
    parameters {
        string(name: 'BROWSER_TYPE', defaultValue: 'chrome', description: 'Type a browser type, should be chrome/firefox')
        string(name, 'TEST_SERVER_URL', defaultValue: '', description: 'Type the test server url')
        string(name: 'NODE', defaultValue: 'win-anthony-demo', description: 'Please choose a windows node to execute this job.')
    }

    stages {
        stage("Initialization") {
            steps {
                script {
                    browser = BROWSER_TYPE?.trim()
                    test_url = TEST_SERVER_URL?.trim()
                    win_node = NODE?.trim()
                }
            }
        }
        stage("Git checkout") {
            steps {
                script {
                    node(win_node) {
                        checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[url: 'https://gitee.com/youqianglinux/jenkins_pipeline_study.git']]])
                    }
                }
            }
        }
        stage("Set key value") {
            steps {
                script {
                    node(win_node) {
                        selenium_test =load env.WORKSPACE + "\\pipeline\\selenium.groovy"
                        config_file = env.WORKSPACE + "\\Configs\\config.properties"
                        try {
                            selenium_test.setKeyValue2("browser", "abc123", config_file)
                            file_content = readFile config_file
                            println file_content
                        } catch (Exception e) {
                            error ("Error met:" + e)
                        }
                    }
                }
            }
        }
        stage ("Run Selenium Test") {
            steps {
                script {
                    node(win_node) {
                        println "Here will start to run selenium test."
                    }
                }
            }
        }
    }
}